package com.lgc.javathread.locktest.interruptTest.interruptTest1;

public class MyThread1 extends Thread {
    private Object obj;

    public MyThread1(String name,Object obj) {
        super(name);
        this.obj = obj;
    }

    @Override
    public void run() {
        try {
            int i = 0;
            while (!isInterrupted()) {
                Thread.sleep(100); // 休眠100ms
                //或
//                synchronized (obj){
//                    obj.wait();
//                }

                i++;
                System.out.println(Thread.currentThread().getName() + " (" + this.getState() + ") loop " + i);
            }
        } catch (InterruptedException e) {
            System.out.println(Thread.currentThread().getName() + " (" + this.getState() + ") catch InterruptedException.");
        }
    }
}
